//
//  UIButton+Extension.swift
//  XinLang
//
//  Created by 张辉 on 16/5/14.
//  Copyright © 2016年 张辉. All rights reserved.
//

import UIKit
extension UIButton {
    /// 创建按钮并指定标题／图像／背景图像
    ///
    /// - parameter title:         标题
    /// - parameter fontSize:      字号，默认17
    /// - parameter titleColor:    字体颜色，默认 darkGrayColor
    /// - parameter imageName:     图像名，可选，默认为 nil
    /// - parameter backImageName: 背景图像名，可选，默认为 nil
    ///
    /// - returns: UIButton
    
    
   convenience init(zh_title title:String?,
       fontSize:CGFloat = 17,
       titleColor:UIColor = UIColor.darkGrayColor(),
       imageName :String? = nil,
       backImageName:String? = nil){
    
       self.init()

    self.setTitle(title, forState: .Normal)
    self.setTitleColor(titleColor, forState: .Normal)
    self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    
    if let imageName = imageName {
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
    
    }
    if let backImageName = backImageName {
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
    
    }
    self.sizeToFit()
    }
    
}